<?php if (!empty($orderList)) : ?>
    <?php foreach ($orderList as $item) : ?>
    <li>
        <div class="li-head flex">
            <!-- <span class="order-id flex-1">订单号：2023172</span> -->
            <span class="order-time">下单时间：<?php echo date('Y-m-d H:i:s', $item[0]->ordertime);?></span>
        </div>
        <dl>
            <?php $total = 0; ?>
            <?php $number = 0; ?>
            <?php $count = count($item); ?>
            <?php foreach($item as $value) : ?>
            <?php $total = bcadd($total, $value->amount_fee, 2); ?>
            <?php $number +=  $value->goods_num; ?>
            <dd>
                <a href="<?php echo site_url('scenic/order/payDetail/'.$value->pay_id); ?>" class="list-name">
                <div class="list-data">
                    <div class="data-name flex flex-align-center">
                        <?php if ($value->calculate_method == 3) : ?>
                            <img src="/skins/scenic/images/saoma.jpg">
                        <?php endif; ?>
                        <div class="data-nen flex-1 am-text-truncate"><?php echo $value->goods_name; ?></div>
                        <i class=""><span>￥</span>
                            <?php echo $value->amount_fee; ?>
                        </i>
                    </div>
                    <p class="flex list-detail">
                        <span class="flex-1">
                            <span>出行时间：<?php echo date('Y-m-d', $value->plantime); ?></span>
                            <span><?php echo $value->goods_num; ?>张</span>
                            <?php if ($value->calculate_method == 3) : ?>
                                <i class="iconfont">&#xe62c;</i>
                            <?php endif; ?>
                        </span>
                        <span class="order-state">
                            <?php 
                            if (((int)$value->bit_pay & 65536) == 65536) {
                                if ($value->bit_use) {
                                    echo '已检票';
                                } elseif (((int)$value->bit_opt& 128) == 128) {
                                    echo '退票审核中';
                                } else {
                                    echo '已付';
                                }
                            } else {
                                if (((int)$value->bit_wan & 8) == 8) {
                                    echo '景区到付';
                                } else {
                                    echo '未支付';
                                }
                            }
                        ?>
                        </span>
                    </p>
                </div>
                </a>
                <?php if ($count > 1) : ?>
                    <?php if ($value->bit_use && $value->status == 0 && date('Y-m-d', strtotime('-1 month')) <= date('Y-m-d', $value->usetime)) : ?>
                    <div class="buttons am-cf">
                        <a href="<?php echo site_url('scenic/order/review/'. $value->order_id); ?>">点评</a>
                    </div>
                     <?php elseif (0 == (((int)$value->bit_opt & 128)) && date('Y-m-d', strtotime('-2 month')) <= date('Y-m-d', $value->plantime)) : //2个月内的可以申请退票和修改。 ?>
                        <?php if (((int)$value->bit_pay & 65536) == 65536) : //订单已付款 ?>
                            
                            <?php if ($value->bit_use == 0 && ((int)$value->bit_wan & 4) != 4 && $value->goods_num > 0) : //订单未使用并且不是OTA对接到系统的订单并且订单数量大于0 ?>
                                <?php
                                    $is_edit = false; 
                                    $is_refund = false;
                                ?>

                                <?php if ($value->is_edit == 1) : //允许改票?>
                                    <?php $is_edit = true;
                                        if (!empty($value->edit_day)) {
                                            $edit_day = date('Y-m-d', strtotime("-{$value->edit_day} days"));
                                            if ( date('Y-m-d') > $edit_day ) {
                                                // $is_edit = false;
                                            } elseif ( date('Y-m-d') == $edit_day ) {
                                                if ($value->edit_time && date('H:i') >= $value->edit_time) {
                                                    $is_edit = false;
                                                }
                                            }
                                        }
                                     ?>
                                <?php endif; ?>
                                <?php if ($value->is_refund == 1) :  //允许退票?>
                                    <?php $is_refund = true;
                                        if (!empty($value->refund_day)) {
                                            $refund_day = date('Y-m-d', strtotime("-{$value->refund_day} days"));
                                            if ( date('Y-m-d') > $refund_day ) {
                                                $is_refund = false;
                                            } elseif ( date('Y-m-d') == $refund_day ) {
                                                if ($value->refund_time && date('H:i') >= $value->refund_time) {
                                                    $is_refund = false;
                                                }
                                            }
                                        }
                                     ?>
                                <?php endif; ?>

                                <?php if ($is_refund || $is_edit) : ?>
                                    <div class="buttons am-cf">
                                        <?php if ($is_edit) : ?>
                                        <a href="<?php echo site_url('scenic/order/modify/'.$value->order_id); ?>">修改</a>
                                        <?php endif; ?>
                                        <?php if ($is_refund) : ?>
                                        <a href="<?php echo site_url('scenic/order/refund/'.$value->order_id); ?>">退票</a>
                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>

                            <?php endif; ?>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php endif; ?>
            </dd>
            <?php endforeach; ?>
        </dl>
        <div class="pay-price">
            <p class="am-text-right">
                <span class="order-num">共<i><?php echo $number; ?></i>张</span>
                <span class="total-price">合计：￥<i><?php echo $total; ?></i></span>
            </p>
        </div>
        
        <?php if ($count == 1) : ?>
            <?php if ($value->bit_use && $value->status == 0 && date('Y-m-d', strtotime('-1 month')) <= date('Y-m-d', $value->usetime)) : ?>
                    <div class="buttons am-cf">
                            <?php if ($value->calculate_method == 3) : ?>
                                <a href="javascript:;" class="code-collection" data-type="1" data-id="<?php echo $value->order_id; ?>">二维码检票</a>
                            <?php endif; ?>
                        <a href="<?php echo site_url('scenic/order/review/'. $value->order_id); ?>">点评</a>
                    </div>
                <?php elseif (0 == (((int)$value->bit_opt & 128)) && date('Y-m-d', strtotime('-2 month')) <= date('Y-m-d', $value->plantime)) : //2个月内的可以申请退票和修改。 ?>
                    <?php if (((int)$value->bit_pay & 65536) == 65536) : //订单已付款 ?>
                        <?php if ($value->bit_use == 0 && ((int)$value->bit_wan & 4) != 4 && $value->goods_num > 0) : //订单未使用并且不是OTA对接到系统的订单并且订单数量大于0 ?>
                            <div class="buttons am-cf">
                            <?php if ($value->calculate_method == 3) : ?>
                                <a href="javascript:;" class="code-collection" data-type="1" data-id="<?php echo $value->order_id; ?>">二维码检票</a>
                            <?php endif; ?>
                            <?php if ($value->is_edit == 1) : //允许改票?>
                                    <?php $is_edit = true;

                                        if (!empty($value->edit_day)) {
                                            $edit_day = date('Y-m-d', strtotime("-{$value->edit_day} days"));
                                            echo $edit_day;
                                            if ( date('Y-m-d') > $edit_day ) {
                                                // $is_edit = false;
                                            } elseif ( date('Y-m-d') == $edit_day ) {
                                                if ($value->edit_time && date('H:i') >= $value->edit_time) {
                                                    $is_edit = false;
                                                }
                                            }
                                        }
                                     ?>
                                     <?php if ($is_edit) : ?>
                                    <a href="<?php echo site_url('scenic/order/modify/'.$value->order_id); ?>">修改</a>
                                    <?php endif; ?>
                                <?php endif; ?>

                                 <?php if ($value->is_refund == 1) :  //允许退票?>
                                    <?php
                                        $is_refund = true;
                                        
                                        if (!empty($value->refund_day)) {
                                            $refund_day = date('Y-m-d', strtotime("-{$value->refund_day} days"));
                                            if ( date('Y-m-d') > $refund_day ) {
                                                $is_refund = false;
                                            } elseif ( date('Y-m-d') == $refund_day ) {
                                                if ($value->refund_time && date('H:i') >= $value->refund_time) {
                                                    $is_refund = false;
                                                }
                                            }
                                        }
                                     ?>
                                     <?php if ($is_refund) : ?>
                                    <a href="<?php echo site_url('scenic/order/refund/'.$value->order_id); ?>">退票</a>
                                    <?php endif; ?>
                                <?php endif; ?>
                        <?php endif;?>
                    <?php else :?>
                        <div class="buttons am-cf">
                            <a href="<?php echo site_url('scenic/payment/payOrderScenic/'.$value->pay_id); ?>">去付款</a>
                        </div>
                    <?php endif;?>
                    </div>
                <?php endif;?>
        <?php else : ?>
            <?php if ($value->bit_use == 0 && 0 == (((int)$value->bit_opt & 128)) && date('Y-m-d', strtotime('-2 month')) <= date('Y-m-d', $value->plantime)) : ?>
                <?php if (((int)$value->bit_pay & 65536) != 65536) : ?>
                    <div class="buttons am-cf">
                        <a href="<?php echo site_url('scenic/payment/payOrderScenic/'.$value->pay_id); ?>">去付款</a>
                    </div>
                <?php elseif ($value->calculate_method == 3 && $count > 1) : ?>
                    <div class="buttons am-cf">
                        <a href="javascript:;" class="code-collection"  data-type="2" data-id="<?php echo $value->pay_id; ?>">合并检票</a>
                    </div>
                <?php endif; ?>
            <?php endif;?>
        <?php endif; ?>
    </li>
    <?php endforeach; ?>
<?php endif; ?>
